<?php
require_once('config.php');
$_prefix = 'wx_lheip_xq_';
$_ext = '.log';
$log_date_format = 'Ymd';
$yesterday = strtotime('today'); //log store as today
$yesterday = date($log_date_format, $yesterday);
//echo $yesterday;
$file_name = NGINX_LOG_PATH . '/' . $_prefix . $yesterday . $_ext;
//echo $file_name;

require_once('logAnalysis.class.php');
$analysis = new logAnalysis($file_name);
$analysis->start();
$result = $analysis->result;

if(DEBUG){
	var_dump($result);exit;
}

$conn = mysql_connect(DB_HOST, DB_USER, DB_PWD);
if(!$conn){
	$analysis->log(mysql_error());
	exit;
}
mysql_select_db(DATA_BASE, $conn);
if(mysql_errno($conn)){
	$analysis->log(mysql_error());
	exit;
}
foreach ($result as $key => $value) {
	$sql = "INSERT INTO `phone_request` (ch_id, u_id, act_id, req_time, req_ip, req_browser, req_system, req_content, req_url) 
	VALUES ('".$value['request']['ch_id']."', '".$value['request']['u_id']."', '".$value['request']['act_id']."', 
		'".$value['time_local']."', '".$value['remote_addr']."', '".$value['http_user_agent']['req_browser']."', 
		'".$value['http_user_agent']['req_system']."', '".$value['request_body']."', '".$value['request']['req_url']."')";
	mysql_query($sql, $conn);
	//echo mysql_error();
	if(mysql_errno($conn)){
		$analysis->log(mysql_error());
	}
}

//close connection
mysql_close($conn);